from enum import IntEnum
from tortoise import fields, models

class Job(models.Model):
    job_id = fields.IntField(pk=True)
    creator = fields.ForeignKeyField('models.User', related_name='created_jobs', on_delete=fields.CASCADE, description="创建人")
    job_name = fields.CharField(max_length=255, description="工作名称")
    company = fields.CharField(max_length=255, description="公司名称")
    detail = fields.TextField(description= "工作详情")
    company_size = fields.IntField(description="企业规模（员工数）")
    salary = fields.DecimalField(max_digits=10, decimal_places=2, description="薪资", ge=0)
    head = fields.CharField(max_length=50, description="负责人")
    posts = fields.CharField(max_length=50,description="负责人职位")
    company_address = fields.TextField(description="企业地址")
    company_industry = fields.CharField(max_length=100, description="企业所属行业")
    company_email = fields.CharField(max_length=100, description="企业邮箱")
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
    updated_at = fields.DatetimeField(auto_now=True, description="更新时间")

    class Meta:
        table = "jobs"
        table_description = "工作表"

class Audit(IntEnum):
    AUDITING = 1  # 审核中
    REJECTED = 2  # 未通过
    APPROVED = 3  # 通过

class ParticipateJob(models.Model):
    """用户参与工作关联表"""
    user = fields.ForeignKeyField('models.User', related_name='participated_jobs', on_delete=fields.CASCADE, description="关联用户")
    job = fields.ForeignKeyField('models.Job', related_name='participants', on_delete=fields.CASCADE, description="关联工作")
    audit = fields.IntEnumField(Audit, default=Audit.AUDITING, description="审核状态")
    class Meta:
        table = "participate_jobs"
        table_description = "用户参与工作关联表"